package com.horizon;

import com.horizon.common.Const;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Interceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        //跨域请求
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE");
        response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept," + Const.ACCESS_TOKEN);
        response.setHeader("Access-Control-Expose-Headers", Const.ACCESS_TOKEN + "," + Const.ACCESS_TOKEN_ALIVE);

        String token = request.getHeader(Const.ACCESS_TOKEN);
        System.out.println("=====" + token);
        return true;
    }
}
